<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"  %>
<%
	response.setHeader("X-Frame-Options","SAMEORIGIN");
	/* 参数 */
	String ckType = request.getParameter("ckType");/* 富文本类型 */
	/* end */
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://"
			+ request.getServerName() + ":" + request.getServerPort()
			+ path + "/";
%>

<html>
<head>
	<jsp:include page="../../public/public.jsp"/>
	
</head>

<body>
<div style="height: 100%">
	<div style="height: 1%"></div>
	<div style="height: 10%;">
		<a id="btn" onclick="addUpdat('add')" 
			href="#" class="easyui-linkbutton" data-options="iconCls:'icon-add'">添加</a>
		<a id="btn" onclick="addUpdat('edit')" style="margin-left: 20px;"
			href="#" class="easyui-linkbutton" data-options="iconCls:'icon-edit'">修改</a>  
	</div>
	
	<table id="dg" style="width:100%;height:90%"
			data-options="
			rownumbers:true,singleSelect:true,pagination:true,
			url:'<%=basePath %>ck/queryCkHtml?sort=yes&&ckType=<%=ckType %>',
			method:'post'">
		<thead>
			<tr id="showThId1">
				<th field="typeName" width="15%" align="center">功能类型</th>
				<th field="title" width="25%" align="center" id="titleId">标题</th>
				<!-- <th field="img" width="22%" align="center">标题图片名称</th> -->
				<th field="summary" width="25%" align="center" id="thNameId">来 源</th>
				<th field="createTime" width="15%" align="center" formatter="formatDatebox">创建时间</th>
				<th field="state" width="15%" align="center" formatter="formatShowDel">显示/删除</th>
			</tr>
		</thead>
	</table>
	
	<script type="text/javascript">
	/* 添加或者修改 */
	function addUpdat(states){
		
		var arr=$('#dg').datagrid('getData');
		var typeName = arr.htmlName;
		if(typeName!=null && typeName!=''){
			typeName = encodeURI(encodeURI(typeName));
		}
		if(states=="edit"){
			var row = $('#dg').datagrid('getSelected');
			if(row==null){
				$.messager.alert("提示","请先选中一条记录","error");
				return;
			}
			var rowid = row.id;
			
			var url = '<%=basePath %>addUpdateHtml.jsp?states='+states+'&ckType=<%=ckType %>&typeName='+typeName+"&rowid="+rowid + "&timestamp=" + new Date().getTime();
		}
		if(states=="add"){
			var url = '<%=basePath %>addUpdateHtml.jsp?states='+states+'&ckType=<%=ckType %>&typeName='+typeName+"&rowid=0";
		}
		var backValue ='';
		var ckWin = <%=ckType %>;
		if(ckWin = 24|| ckWin==25){
			backValue =window.open(url,"",'edge:Raised;center:Yes;help:Yes;resizable:no;status:No;dialogWidth:1200px;DialogHeight=650px');
		}else{
			backValue =window.open(url,"",'edge:Raised;center:Yes;help:Yes;resizable:no;status:No;dialogWidth:1200px;DialogHeight=650px');
		}
		
		if(backValue=="success"){
	    	$('#dg').datagrid("reload");
		}
	}
		$(function(){
			var pager = $('#dg').datagrid().datagrid('getPager');				
		})
		
	/* 对	显示/删除   进行 format */
	function formatShowDel(value,row,index){
		
		if (value == null || value == '') {  
		        return '';  
		}
		if(value=="1"){
			
			return '<span><a href="#" style="text-decoration:none;color:green" onclick=showdel('+row.id+','+value+'); >已显示</a></span>';
		}
		if(value=="2"){
			return '<span><a href="#"  style="text-decoration:none;color:red " onclick=showdel('+row.id+','+value+'); >已删除</a></span>';
		}
	}
	
		/* 点击 显示 或者 删除  修改状态 */
		function showdel(id,value){
			
			var state = "";
			var delName="";
			if(value=='1'){
				state='2';
				delName="删除";
			}
			if(value=='2'){
				state='1';
				delName="显示";
			}
			  
			$.messager.confirm('确认','您确认想要 [ '+delName+' ] 数据吗？',function(r){    
			    if (r){    
			    	$.ajax({  
						url:'<%=basePath %>ck/updateCkHtml',
						type:'post',
						data:{
						"id":id,
						"state":state
						},
						dataType:'json',
						error:function(){
							$.messager.alert("提示",delName+"异常","error");
						}, 
						success:function(map){ 
							var row = map.row;
							if(row>=0){
								$.messager.alert("提示",delName+"成功","info");
								$('#dg').datagrid("reload");
								return;
							}else{
								$.messager.alert("提示",delName+"失败","error");
								return;
							}
						}  
					});    
			    }    
			});
			
			
			
		}
		
	/*对创建时间format  */	
	function formatDatebox(value) {  
	    if (value == null || value == '') {  
	        return '';  
	    }  
	    var dt;  
	    if (value instanceof Date) {  
	        dt = value;  
	    } else {  
	        dt = new Date(value);  
	    }  
	  
	    return dt.format("yyyy-MM-dd hh:mm:ss"); //扩展的Date的format方法(上述插件实现)  
	}
		
		Date.prototype.format = function (format) {  
		    var o = {  
		        "M+": this.getMonth() + 1, // month  
		        "d+": this.getDate(), // day  
		        "h+": this.getHours(), // hour  
		        "m+": this.getMinutes(), // minute  
		        "s+": this.getSeconds(), // second  
		        "q+": Math.floor((this.getMonth() + 3) / 3), // quarter  
		        "S": this.getMilliseconds()  
		        // millisecond  
		    }  
		    if (/(y+)/.test(format))  
		        format = format.replace(RegExp.$1, (this.getFullYear() + "")  
		            .substr(4 - RegExp.$1.length));  
		    for (var k in o)  
		        if (new RegExp("(" + k + ")").test(format))  
		            format = format.replace(RegExp.$1, RegExp.$1.length == 1 ? o[k] : ("00" + o[k]).substr(("" + o[k]).length));  
		    return format;  
	} 
	</script>
	<script type="text/javascript">
		var ckType  = <%=ckType %>;
		if(ckType==24||ckType==25){
			$("#titleId").html("联系方式");
			$("#thNameId").html("联系内容");
		}
		
	</script>

</div>
</body>
</html>
